<?php
include("../../tools/session.php");
include("../../tools/controls.php");
include("../../tools/pub.php");

// 如果登录失败、无权限访问，那么采取相应措施
if (!($is_login_success === true)) { session_hop_page("../index.php"); exit(); }
if (!power_check(0)) { include("tpl-inc-wp.php"); $tpl->display($oa_tpl_path . "/no-power.html"); exit(); }

/*-- 以下是实际内容 --*/
include("../../tools/mysql.php");
db_connect();

$page_status = $_POST["page_status"];
$per_page = 10;

// 正常状态下的页面
if (!$page_status)
{
	include("tpl-inc-wp.php");
	
	// $sql = "SELECT ceil(count(id)/" . $per_page . ") num FROM view_user_archive";
	$sql = "SELECT count(id) num FROM view_user_archive";
	$re = db_query_once($sql);
	
	// $tpl->assign("page_num", $re["num"]);
	$tpl->assign("wholepage", $re["num"]);
	$tpl->display($oa_tpl_path . "/default/edit_person.html");
}
// 需要修改的员工信息提交过来时
// 页面参数 page_status 值为 1
elseif ($page_status == 1)
{
	$id = $_POST["id"];
	$sql = "SELECT * FROM view_user_archive WHERE id=" . $id;
	$re = db_query_once($sql);

	// $birth = explode("-", $re["birth"]);
	// $graduate = explode("-", $re["graduate"]);

	header("content-type: text/xml");
	echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
	echo "<userinfo>\n";
	
	// <![CDATA[" . $re[""] . "]]>
	echo "<identity><![CDATA[" . $re["identity"] . "]]></identity>\n";
	echo "<sex><![CDATA[" . $re["sex"] . "]]></sex>\n";
	echo "<birth><![CDATA[" . $re["birth"] . "]]></birth>\n";
	echo "<tel><![CDATA[" . $re["tel"] . "]]></tel>\n";
	echo "<phone><![CDATA[" . $re["phone"] . "]]></phone>\n";
	echo "<qq><![CDATA[" . $re["qq"] . "]]></qq>\n";
	echo "<email><![CDATA[" . $re["email"] . "]]></email>\n";
	echo "<address><![CDATA[" . $re["address"] . "]]></address>\n";
	echo "<marriage><![CDATA[" . $re["marriage"] . "]]></marriage>\n";
	echo "<culture><![CDATA[" . $re["culture"] . "]]></culture>\n";
	echo "<degree><![CDATA[" . $re["degree"] . "]]></degree>\n";
	echo "<diploma_num><![CDATA[" . $re["diploma_num"] . "]]></diploma_num>\n";
	echo "<graduate><![CDATA[" . $re["graduate"] . "]]></graduate>\n";
	echo "<school><![CDATA[" . $re["school"] . "]]></school>\n";
	echo "<spec_field><![CDATA[" . $re["spec_field"] . "]]></spec_field>\n";
	echo "<job_q_c><![CDATA[" . $re["job_q_c"] . "]]></job_q_c>\n";
	echo "<grade><![CDATA[" . $re["grade"] . "]]></grade>\n";
	echo "<census_reg><![CDATA[" . $re["census_reg"] . "]]></census_reg>\n";
	echo "<census_class><![CDATA[" . $re["census_class"] . "]]></census_class>\n";
	
	echo "</userinfo>\n";
}
// 分页时
// 页面参数 page_status 值为 2
elseif ($page_status == 2)
{
	header("content-type: text/xml");
	echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
	echo "<people>\n";

	$page = $_POST["page"];
	$page = (!$page) ? 1 : $page;

	$page_min = $per_page * ($page - 1); 
	$sql = "SELECT id, username, register_time FROM user WHERE deleted='0' ORDER BY register_time DESC LIMIT " . $page_min . "," . $per_page;
	$re = db_query($sql);
	
	$str = "";
	foreach ($re as $v)
	{
        	$str .= "<item>\n";
        	$str .= "<id>" . $v["id"] . "</id>\n";
        	$str .= "<username>" . $v["username"] . "</username>\n";
        	$str .= "<register_time>" . $v["register_time"] . "</register_time>";
        	$str .= "</item>\n";
	}
	
	echo $str;
	
	echo "</people>\n";
}
// 提交修改数据时
// 页面参数 page_status 为 3
elseif($page_status == 3)
{
	$username = $_POST["username"];
	// $id = $_POST["id"];
	$identity = $_POST["identity"];
	$sex = $_POST["sex"];
	$birth = $_POST["birth"];
	$tel = $_POST["tel"];	
	$phone = $_POST["phone"];
	$qq = $_POST["qq"];
	$email = $_POST["email"];
	$address = $_POST["address"];	
	$marriage = $_POST["marriage"];
	$culture = $_POST["culture"]; 
	$degree = $_POST["degree"];
	$diploma_num = $_POST["diploma_num"];
	$graduate = $_POST["graduate"];
	$school = $_POST["school"];
	$spec_field = $_POST["spec_field"];
	$job_q_c = $_POST["job_q_c"];	
	$grade = $_POST["grade"];
	$census_reg = $_POST["census_reg"];
	$census_class = $_POST["census_class"];
	
	$sql = "UPDATE archive SET identity='".$identity."', sex='".$sex."', birth='".$birth."', tel='".$tel."', phone='".$phone."', "
				. " qq='".$qq."', email='".$email."', address='".$address."', marriage='".$marriage."', "
				. " culture='".$culture."', degree='".$degree."', diploma_num='".$diploma_num."', graduate='".$graduate."', "
				. " school='".$school."', spec_field='".$spec_field."', job_q_c='".$job_q_c."', grade='".$grade."', "
				. " census_reg='". $census_reg ."', census_class='".$census_class."' WHERE username='" . $username . "'";
	// echo (!db_exec($sql)) ? "failed!" : "success!";
	$log_str = array("修改员工“" . $username . "”的信息成功！", "修改员工“" . $username . "”的信息失败！");
	echo check_status_write_to_log(db_exec($sql), $log_str, TRUE);
}
?>

